# -*- coding: utf-8 -*-
import re
import scrapy
from scrapy.http import Request
from myproject.items import BtsoPwItem
from urllib import parse

class BtsoSpider(scrapy.Spider):
    name = 'btso'
    handle_httpstatus_list = [403]
    allowed_domains = ['runbt.co']
    start_urls = ['http://www.runbt.co/list/幼女/1/']

    def parse(self, response):
        lis = response.css('.main .mlist li')
        for li in lis:
            url = li.css('.dInfo a:first-child::attr(href)').extract_first()
            title = li.css('.T1  a::text').extract_first()
            if title:
               print("title--------" + title)
            size = li.css('.BotInfo dt span:first-child::text').extract_first()
            item = BtsoPwItem()
            item['title'] = title
            item['mp4_url'] = url
            item['tag'] = '幼女'
            item['size'] = size
            item['desc'] = "幼女"
            yield item
        next_url = response.css('#mpages  .flag_pg:last-child::attr(href)').extract_first()
        if next_url:
           next_url = parse.urljoin(response.url, next_url)
           print(next_url)
           yield Request(url=next_url, callback=self.parse)
        pass





